package com;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class TestCalendar {
	public static void main(String[] args) {
		// 取年初
        Long czt = dateTransformGTM8TimeZone(new Date(), "GMT-5");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(czt));
//        c.set(c.get(Calendar.YEAR), Calendar.JANUARY, 1, 0, 0, 0);

        c.add(Calendar.DAY_OF_MONTH, 0);
        System.out.println(c.getTime());
	}
	
	public static Long dateTransformGTM8TimeZone(Date sourceDate, String targetZone) {
        return dateTransformBetweenTimeZone(sourceDate, "GMT+8", targetZone);
    }

    public static Long dateTransformBetweenTimeZone(Date sourceDate, String sourceZone, String targetZone) {
        TimeZone sourceTimeZone = TimeZone.getTimeZone(sourceZone);
        TimeZone targetTimeZone = TimeZone.getTimeZone(targetZone);
        return dateTransformBetweenTimeZone(sourceDate, sourceTimeZone, targetTimeZone);
    }
    
    public static Long dateTransformBetweenTimeZone(Date sourceDate, TimeZone sourceTimeZone, TimeZone targetTimeZone) {
        Long targetTime = sourceDate.getTime() - sourceTimeZone.getRawOffset() + targetTimeZone.getRawOffset();
        return targetTime;
    }

}
